<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('岗位查看')" />
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>岗位名称：</label>
                            <input type="text" name="postName"/>
                        </li>
                        <li>
                            <label>开始时间：</label>
                            <input type="text" class="time-input" placeholder="请选择招聘开始时间" name="startTime"/>
                        </li>
                        <li>
                            <label>结束时间：</label>
                            <input type="text" class="time-input" placeholder="请选择招聘结束时间" name="endTime"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer" />
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('wstudy:post:edit')}]];
    var removeFlag = [[${@permission.hasPermi('wstudy:post:remove')}]];
    var postStatusDatas = [[${@dict.getType('wst_post_status')}]];
    var statusDatas = [[${@dict.getType('wst_post_status')}]];
    var postUsers = [[${postUsers}]];
    var applies = [[${applies}]];
    var prefix = ctx + "wstudy/post";
    var prefixRecord = ctx + "wstudy/record";
    var prefixProcess = ctx + "wstudy/process";
    var prefixPE = ctx + "wstudy/examine";
    var roleKey = "administer";
    var prefixApply = ctx + "wstudy/apply";
    let status = false;
    let applyInfo = true;
    $.each(postUsers,function (item,index) {
        if(item.status=='ON' || item.postId == postId){
            applyInfo=false
        }
    })
    $(function() {
        var options = {
            url: prefix + "/postUserData",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "岗位管理",
            columns: [{
                checkbox: true
            },
                {
                    field: 'postId',
                    title: 'ID',
                    visible: false
                },
                {
                    field: 'postCode',
                    title: '岗位编码'
                },
                {
                    field: 'postName',
                    title: '岗位名称'
                },
                {
                    field: 'needNum',
                    title: '招聘人数'
                },
                {
                    field: 'salary',
                    title: '工资'
                },
                {
                    field: 'status',
                    title: '状态',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(statusDatas, value);
                    }
                },
                {
                    field: 'workplace',
                    title: '工作地址'
                },
                {
                    field: 'startTime',
                    title: '招聘开始时间'
                },
                {
                    field: 'endTime',
                    title: '招聘结束时间'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        let  approvalFlag = row.status == 'WAITING_FOR_APPROVAL';
                        let failFlag = row.status == 'APPROVAL_FAILED';

                        actions.push('<a class="btn btn-info btn-xs " href="javascript:void(0)" onclick="details(\'' + row.postId + '\')"><i class="fa fa-search"></i>详情</a> ');
                        if (applyInfo){
                            let postStatus = true;
                            $.each(applies,function (index,item) {
                                if (item.postId==row.postId){
                                    postStatus=false;
                                }
                            })
                            if (postStatus){
                                actions.push('<a class="btn btn-success btn-xs " href="javascript:void(0)" onclick="apply(\'' + row.postId + '\')"><i class="fa fa-edit"></i>申请</a> ');
                            }else{
                                actions.push('<a class="btn btn-success btn-xs disabled" href="javascript:void(0)" onclick="apply(\'' + row.postId + '\')"><i class="fa fa-edit"></i>申请</a> ');
                            }
                        }
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });
    function details(id) {
        $.modal.openTab("详情",prefix+"/details/"+id)
    }

    function record(postId) {
        parent.layer.open({
            type: 2,
            area: ['800px','500px'],
            fix: true,
            maxmin: true,
            shade: 0.3,
            shadeClose:true,
            title: '审核记录',
            content: prefixRecord+"/examine/"+postId,
            btn: ['提交','取消']
            ,success:function (layero, index){    //弹出层加载成功后执行
                let iframeWin = parent.window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：
            }
            ,yes: function(index, layero){
                let iframeWin = parent.window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：
                let examineUserId = iframeWin.submit();
                let params = {
                    postId:postId,
                    "params[exmineUserId]":examineUserId
                }
                $.operate.post(prefixProcess+"/submit",params);
            }
            ,cancel: function(){

            }
        });
    }

    function apply(postId) {
        // 1. 检验学生是否有资格
        $.ajax({
            url: prefixApply+"/studentPost",
            type: 'post',
            cache: false,
            async : false,
            data:{"postId":postId},
            dataType: "json",
            success: function (result) {
                status=result;
            }
        });
        // 2. 符合资格则允许申请
        if (status){
            $.modal.openTab("申请信息",prefixApply+"/add/"+postId);
        }else{
            $.modal.msgWarning("您的条件不符合！");
        }
    }
</script>
</body>
</html>